﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Common.Library;
using OnlineVideos.Services.FileStoreService;
using OnlineVideos.Services;
using Microsoft.Phone.Controls;
using System.Collections.Generic;
using Common.Services;


namespace Common.Library
{
    public static class CloudService
    {
        public static string SendMailWebTile(string subject, string body, string ToAddress)
        {

            try
            {

                ServiceManager.SendMailToAppAsync("support@lartsoft.com", ToAddress, subject, body, service_SendMailCompleted);
                return ToAddress;
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in SendMailWebTile Method In CloudService.cs file.", ex);
                return null;
            }
        }
        public static string SendMail(string subject, string body, string fromAddress)
        {

            try
            {
                string Toaddress = SettingsHelper.getStringValue("ToEmailid");
                if (Toaddress == "")
                {
                    Toaddress = "feedback.at@Lartsoft.com";
                }
                if (string.IsNullOrEmpty(fromAddress))
                {
                    fromAddress = SettingsHelper.getStringValue("FromEmailid");
                }
                ServiceManager.SendMailToAppAsync(fromAddress, Toaddress, subject, body, service_SendMailCompleted);

                return fromAddress;
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in SendMail Method In CloudService.cs file.", ex);
                return null;
            }
        }

        //TODO: finish this in the consumer classes
        static void service_SendMailCompleted(object sender, SendMailCompletedEventArgs e)
        {
            try
            {
                if (e.Error == null)
                {

                    MessageBox.Show("Feedback sent successfully");

                    ((PhoneApplicationFrame)Application.Current.RootVisual).GoBack();


                }
                else
                {
                    MessageBox.Show("Failed to send feedback, try again later.");
                    ((PhoneApplicationFrame)Application.Current.RootVisual).GoBack();
                }
            }
            catch (Exception ex)
            {
                
              Exceptions.SaveOrSendExceptions("Exception in service_SendMailCompleted Method In CloudService.cs file.", ex);
            }
            
            
        }
    }
}
